package emulator.util.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import emulator.util.ByteHelper;

public class FileInfoPrg implements FileInfo {

	private int start_address;
	private int block_size;

	public FileInfoPrg(String file_name)
	{
		File file = new File(file_name);
		block_size = (int)file.length() - 2;
		start_address = 0;
		FileInputStream file_stream = null;
		try {
			file_stream = new FileInputStream(file);
			start_address = ByteHelper.readWord(file_stream);
		} catch (FileNotFoundException e) {
		} catch (IOException e) {
		}
		finally
		{
			if (file_stream != null)
				try { file_stream.close(); } catch (IOException e) {}
		}
	}

	@Override
	public int getBlockSize() {
		return block_size;
	}

	@Override
	public int getFormat() {
		return FileHelper.FILE_FORMAT_PRG;
	}

	@Override
	public int getStartAddress() {
		return start_address;
	}


	@Override
	public FileLoadStrategy getLoadStrategy() {
		return new FileLoadStrategySkipPrefix(2);
	}


	@Override
	public FileSaveStrategy getSaveStrategy() {
		return new FileSaveStrategyPrg();
	}

}
